import Api from '../api'
import { uploadFileTimeout } from '@/config/settings'

class CommonApi extends Api {
    // 资产模块的下载文件
    static downloadPath = '/property/common/import/result/download'
    // 路面检查数据的模板下载
    static templatePath = '/checkData/common/downloadTemplateFile'

    constructor(scope) {
        super()
        this.scope = scope
    }

    resolvePath(path) {
        return this.scope + path
    }

    records(data) {
        const path = this.resolvePath('/list')
        return this.post(path, data)
    }

    // 新增或者更新
    saveOrUpdate(data) {
        const path = this.resolvePath('/saveOrUpdate')
        return this.post(path, data)
    }

    delete(data) {
        const path = this.resolvePath('/delete')
        return this.post(path, data)
    }

    detail(data) {
        const path = this.resolvePath('/detail')
        return this.post(path, data)
    }

    // 提交
    submit(data) {
        const path = this.resolvePath('/submit')
        return this.post(path, data)
    }

    // 撤回
    recall(data) {
        const path = this.resolvePath('/withdraw')
        return this.post(path, data)
    }

    // 中止
    stop(data) {
        const path = this.resolvePath('/stop')
        return this.post(path, data)
    }

    // 启动
    start(data) {
        const path = this.resolvePath('/start')
        return this.post(path, data)
    }

    // 添加
    add(data) {
        const path = this.resolvePath('/add')
        return this.post(path, data)
    }

    // 名称唯一性验证
    uniqueCheck(data) {
        const path = this.resolvePath('/nameCheck')
        return this.post(path, data)
    }

    // 导入文件
    import(form) {
        const headers = { 'content-type': 'multipart/form-data' }
        const path = this.resolvePath('/import')
        return this.post(path, form, {
            headers,
            timeout: uploadFileTimeout
        })
    }

    // 各个模块的导出地址
    customDownloadPath() {
        const path = this.resolvePath('/export')
        return path
    }

    // 根据桩号获取经纬度
    getLngLatByStake(data) {
        const path = '/property/common/getLngLatByStake'
        return this.post(path, data)
    }
}

export default CommonApi
